/**
 * @projectName: pet-joy-home
 * @author: 小飞
 * @description: TODO
 * @date: 2024/9/8 12:17
 * @version: 1.0
 */
package com.home.result;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class OutResponse {
    public static void getResponse(HttpServletResponse response, Integer code, String errMsg) throws IOException {
        response.setStatus(code);
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter out = response.getWriter();

        ObjectMapper objectMapper = new ObjectMapper();
        String errorMsg = objectMapper.writeValueAsString(Result.failed(code,errMsg));
        out.write(errorMsg);
        out.flush();
        out.close();
    }
}
